<template>
  <el-form :model="form" :rules="rules" ref="formRef">
    <el-form-item label="门店名称" prop="storeName" :label-width="formLabelWidth">
      <el-input v-model="form.storeName"></el-input>
    </el-form-item>
    <el-form-item label="门店地址" prop="address" :label-width="formLabelWidth">
      <el-input type="textarea" :rows="4" v-model="form.address"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark" :label-width="formLabelWidth">
      <el-input type="textarea" :rows="4" v-model="form.remark"></el-input>
    </el-form-item>
    <el-form-item :label-width="formLabelWidth">
      <el-button plain @click="resetForm('formRef')">取消</el-button>
      <el-button type="primary" @click="submitForm('formRef')">确定</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  name: "",
  props: ["data"],
  data() {
    return {
      form: {
        storeName: "",
        address: "",
        remark:""
      },
      formLabelWidth: "150px",
      rules: {
         storeName: [
          { required: true, message: "请输入门店名称", trigger: "blur" },
          {  max: 50, message: '长度不能超过50个字符', trigger: 'blur' }
        ],
        address: [
          { required: true, message: "请输入门店地址", trigger: "blur" },
          {  max: 50, message: '长度不能超过50个字符', trigger: 'blur' }
        ],
        remark: [
          { required: true, message: "请输入备注", trigger: "blur" },
          {  max: 50, message: '长度不能超过50个字符', trigger: 'blur' }
        ]
      }
    };
  },
  components: {},
  computed: {},
  beforeMount() {},
  mounted() {
    this.form = this.data;
  },
  methods: {
    resetForm(formName) {
      this.$emit("cancel", false);
    },
    submitForm(formName) {
      this.form.storeName = this.form.storeName.replace(/^\s+|\s+$/g, "");
      this.form.address = this.form.address.replace(/^\s+|\s+$/g, "");
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$service
            .updateStore({
              toreId: this.data.storeId,
              name: this.form.storeName,
              address: this.form.address,
              remark: this.form.remark
            })
            .then(res => {
              if (res.code == "H0900") {
                this.$message.error(res.message);
              } else {
                this.$message({
                  message: "修改成功",
                  type: "success"
                });
                this.$refs[formName].resetFields();
                this.$emit("submit", false);
              }
            });
        }
      });
    }
  },
  watch: {}
};
</script>
<style scoped>
</style>
